<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>勾股定理的几何证明</title>
    <style>
        :root {
            --primary-color: #4a90e2;
            --secondary-color: #7ed321;
            --text-color: #333;
            --bg-color: #f9f9f9;
            --light-gray: #eee;
        }

        body {
            font-family: 'Arial', sans-serif;
            line-height: 1.6;
            color: var(--text-color);
            background-color: var(--bg-color);
            margin: 0;
            padding: 20px;
            max-width: 1000px;
            margin: 0 auto;
        }

        h1 {
            color: var(--primary-color);
            text-align: center;
            margin-bottom: 20px;
        }

        .container {
            display: flex;
            flex-direction: column;
            gap: 30px;
        }

        .description {
            background-color: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            margin-bottom: 20px;
        }

        .proof-container {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 20px;
        }

        .controls {
            display: flex;
            gap: 10px;
            justify-content: center;
            margin-bottom: 20px;
        }

        button {
            padding: 10px 20px;
            border: none;
            border-radius: 4px;
            background-color: var(--primary-color);
            color: white;
            cursor: pointer;
            font-size: 16px;
            transition: background-color 0.3s;
        }

        button:hover {
            background-color: #357abd;
        }

        button:disabled {
            background-color: #cccccc;
            cursor: not-allowed;
        }

        #pauseBtn {
            background-color: #f5a623;
        }

        #pauseBtn:hover {
            background-color: #e69500;
        }

        #resetBtn {
            background-color: #d0021b;
        }

        #resetBtn:hover {
            background-color: #b50118;
        }

        .step-text {
            opacity: 0;
            text-align: center;
            max-width: 80%;
            margin: 10px auto;
            padding: 15px;
            background-color: rgba(255, 255, 255, 0.9);
            border-radius: 8px;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
            transform: translateY(20px);
            transition: opacity 0.5s, transform 0.5s;
        }

        .step-text.visible {
            opacity: 1;
            transform: translateY(0);
        }

        svg {
            max-width: 100%;
            height: auto;
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            overflow: visible;
        }

        .square {
            fill: var(--secondary-color);
            opacity: 0.7;
            stroke: var(--primary-color);
            stroke-width: 2;
        }

        .triangle {
            fill: var(--primary-color);
            opacity: 0.7;
            stroke: var(--primary-color);
            stroke-width: 2;
        }

        .grid-line {
            stroke: var(--light-gray);
            stroke-width: 1;
        }

        .text-label {
            font-size: 16px;
            fill: var(--text-color);
            text-anchor: middle;
        }

        .highlight {
            stroke: #d0021b;
            stroke-width: 3;
            stroke-dasharray: 5, 5;
        }

        @media (max-width: 768px) {
            body {
                padding: 10px;
            }

            .description {
                padding: 15px;
            }

            .step-text {
                padding: 10px;
                font-size: 14px;
            }

            svg {
                width: 100%;
            }
        }
    </style>
</head>

<body>
    <noscript>
        <style>
            body {
                display: none !important;
            }
        </style>
        <meta http-equiv="refresh" content="0; url=about:blank">
    </noscript>
    <script src="security.js"></script>
    <div class="container">
        <h1>勾股定理的几何证明</h1>

        <div class="description">
            <p>勾股定理（毕达哥拉斯定理）指出：在直角三角形中，斜边的平方等于两直角边的平方和。</p>
            <p>数学表达式：在△ABC中，若∠C=90°，则有：</p>
            <div style="text-align: center; font-size: 24px; margin: 10px 0;">
                a² + b² = c²
            </div>
            <p>下面通过几何方法证明这一重要定理。</p>
        </div>

        <div class="proof-container">
            <div class="controls">
                <button id="startBtn">开始动画</button>
                <button id="pauseBtn" disabled>暂停</button>
                <button id="resetBtn">重置</button>
            </div>

            <div class="step-text" id="step1">
                <p>1. 准备一个边长为a+b的正方形，内部有四个全等的直角三角形（两直角边分别为a和b，斜边为c）。</p>
            </div>

            <svg id="proofSvg1" width="500" height="500" viewBox="0 0 500 500">
                <!-- 背景网格 -->
                <g class="grid">
                    <line class="grid-line" x1="0" y1="250" x2="500" y2="250" />
                    <line class="grid-line" x1="250" y1="0" x2="250" y2="500" />
                    <!-- 更多网格线可以添加在这里 -->
                </g>

                <!-- 外部大正方形 -->
                <rect x="50" y="50" width="400" height="400" fill="none" stroke="var(--primary-color)"
                    stroke-width="2" />

                <!-- 四个直角三角形 -->
                <polygon class="triangle" points="50,50 250,50 50,250" />
                <polygon class="triangle" points="250,50 450,50 450,250" />
                <polygon class="triangle" points="450,250 450,450 250,450" />
                <polygon class="triangle" points="250,450 50,450 50,250" />

                <!-- 内部小正方形 -->
                <rect class="square" x="200" y="200" width="100" height="100" />

                <!-- 标签 -->
                <text class="text-label" x="150" y="150">a</text>
                <text class="text-label" x="350" y="150">b</text>
                <text class="text-label" x="350" y="350">a</text>
                <text class="text-label" x="150" y="350">b</text>
                <text class="text-label" x="250" y="250">c</text>
                <text class="text-label" x="250" y="480" text-anchor="middle">边长 = a + b</text>
            </svg>

            <div class="step-text" id="step2">
                <p>2. 大正方形的面积可以表示为：(a+b)² = 4×(1/2ab) + c²</p>
            </div>

            <svg id="proofSvg2" width="500" height="500" viewBox="0 0 500 500">
                <!-- 背景网格 -->
                <g class="grid">
                    <line class="grid-line" x1="0" y1="250" x2="500" y2="250" />
                    <line class="grid-line" x1="250" y1="0" x2="250" y2="500" />
                </g>

                <!-- 外部大正方形 -->
                <rect x="50" y="50" width="400" height="400" fill="none" stroke="var(--primary-color)"
                    stroke-width="2" />

                <!-- 四个直角三角形 -->
                <polygon class="triangle" points="50,50 250,50 50,250" />
                <polygon class="triangle" points="250,50 450,50 450,250" />
                <polygon class="triangle" points="450,250 450,450 250,450" />
                <polygon class="triangle" points="250,450 50,450 50,250" />

                <!-- 内部小正方形 -->
                <rect class="square" x="200" y="200" width="100" height="100" />

                <!-- 高亮显示三角形和正方形 -->
                <polygon class="triangle highlight" points="50,50 250,50 50,250">
                    <animate attributeName="opacity" values="0.7;0.3;0.7" dur="3s" repeatCount="indefinite" />
                </polygon>
                <rect class="square highlight" x="200" y="200" width="100" height="100">
                    <animate attributeName="opacity" values="0.7;0.3;0.7" dur="3s" repeatCount="indefinite" />
                </rect>

                <!-- 标签 -->
                <text class="text-label" x="150" y="150">a</text>
                <text class="text-label" x="350" y="150">b</text>
                <text class="text-label" x="350" y="350">a</text>
                <text class="text-label" x="150" y="350">b</text>
                <text class="text-label" x="250" y="250">c</text>
                <text class="text-label" x="250" y="480" text-anchor="middle">面积 = 4×(1/2ab) + c²</text>
            </svg>

            <div class="step-text" id="step3">
                <p>3. 展开计算：(a+b)² = 2ab + c²</p>
            </div>

            <svg id="proofSvg3" width="500" height="500" viewBox="0 0 500 500">
                <!-- 背景网格 -->
                <g class="grid">
                    <line class="grid-line" x1="0" y1="250" x2="500" y2="250" />
                    <line class="grid-line" x1="250" y1="0" x2="250" y2="500" />
                </g>

                <!-- 外部大正方形 -->
                <rect x="50" y="50" width="400" height="400" fill="none" stroke="var(--primary-color)"
                    stroke-width="2" />

                <!-- 四个直角三角形 -->
                <polygon class="triangle" points="50,50 250,50 50,250" />
                <polygon class="triangle" points="250,50 450,50 450,250" />
                <polygon class="triangle" points="450,250 450,450 250,450" />
                <polygon class="triangle" points="250,450 50,450 50,250" />

                <!-- 内部小正方形 -->
                <rect class="square" x="200" y="200" width="100" height="100" />

                <!-- 高亮显示展开过程 -->
                <rect x="50" y="50" width="400" height="400" fill="none" stroke="#d0021b" stroke-width="3"
                    stroke-dasharray="5,5">
                    <animate attributeName="opacity" values="0;1;0" dur="3s" fill="freeze" />
                </rect>

                <!-- 标签 -->
                <text class="text-label" x="150" y="150">a</text>
                <text class="text-label" x="350" y="150">b</text>
                <text class="text-label" x="350" y="350">a</text>
                <text class="text-label" x="150" y="350">b</text>
                <text class="text-label" x="250" y="250">c</text>
                <text class="text-label" x="250" y="480" text-anchor="middle">(a+b)² = 2ab + c²</text>
            </svg>

            <div class="step-text" id="step4">
                <p>4. 重新排列大正方形中的四个三角形，形成两个较小的正方形。</p>
            </div>

            <svg id="proofSvg4" width="500" height="500" viewBox="0 0 500 500">
                <!-- 背景网格 -->
                <g class="grid">
                    <line class="grid-line" x1="0" y1="250" x2="500" y2="250" />
                    <line class="grid-line" x1="250" y1="0" x2="250" y2="500" />
                </g>

                <!-- 外部大正方形 -->
                <rect x="50" y="50" width="400" height="400" fill="none" stroke="var(--primary-color)"
                    stroke-width="2" />

                <!-- 重新排列的四个直角三角形 -->
                <polygon class="triangle" points="50,50 250,50 50,250" />
                <polygon class="triangle" points="250,50 450,50 450,250" />
                <polygon class="triangle" points="450,250 450,450 250,450" />
                <polygon class="triangle" points="250,450 50,450 50,250" />

                <!-- 两个小正方形 -->
                <rect class="square" x="100" y="100" width="100" height="100" />
                <rect class="square" x="300" y="100" width="100" height="100" />

                <!-- 动画：移动正方形 -->
                <rect class="square" x="200" y="200" width="100" height="100">
                    <animateTransform attributeName="transform" type="translate" values="0,0; -100,-100; -100,-100"
                        dur="3s" fill="freeze" />
                    <animate attributeName="opacity" values="1;0;0" dur="3s" fill="freeze" />
                </rect>
                <rect class="square" x="200" y="200" width="100" height="100">
                    <animateTransform attributeName="transform" type="translate" values="0,0; 100,100; 100,100" dur="3s"
                        fill="freeze" />
                    <animate attributeName="opacity" values="1;0;0" dur="3s" fill="freeze" />
                </rect>

                <!-- 标签 -->
                <text class="text-label" x="150" y="150">a²</text>
                <text class="text-label" x="350" y="150">b²</text>
                <text class="text-label" x="250" y="480" text-anchor="middle">面积 = a² + b² + 2ab</text>
            </svg>

            <div class="step-text" id="step5">
                <p>5. 比较两种排列方式的面积表达式：(a+b)² = a² + b² + 2ab = 2ab + c²</p>
                <p>两边消去2ab，得到：a² + b² = c²</p>
                <p>勾股定理得证！</p>
            </div>

            <svg id="proofSvg5" width="500" height="500" viewBox="0 0 500 500">
                <!-- 背景网格 -->
                <g class="grid">
                    <line class="grid-line" x1="0" y1="250" x2="500" y2="250" />
                    <line class="grid-line" x1="250" y1="0" x2="250" y2="500" />
                </g>

                <!-- 外部大正方形 -->
                <rect x="50" y="50" width="400" height="400" fill="none" stroke="var(--primary-color)"
                    stroke-width="2" />

                <!-- 四个直角三角形 -->
                <polygon class="triangle" points="50,50 250,50 50,250" />
                <polygon class="triangle" points="250,50 450,50 450,250" />
                <polygon class="triangle" points="450,250 450,450 250,450" />
                <polygon class="triangle" points="250,450 50,450 50,250" />

                <!-- 两个小正方形 -->
                <rect class="square" x="100" y="100" width="100" height="100" />
                <rect class="square" x="300" y="100" width="100" height="100" />

                <!-- 高亮显示等式 -->
                <text class="text-label" x="250" y="400" font-size="24" text-anchor="middle" fill="#d0021b">a² + b² =
                    c²</text>
                <rect x="150" y="380" width="200" height="40" fill="none" stroke="#d0021b" stroke-width="2"
                    stroke-dasharray="5,5">
                    <animate attributeName="opacity" values="0;1;1" dur="2s" fill="freeze" />
                </rect>

                <!-- 标签 -->
                <text class="text-label" x="150" y="150">a²</text>
                <text class="text-label" x="350" y="150">b²</text>
                <text class="text-label" x="250" y="480" text-anchor="middle">勾股定理：a² + b² = c²</text>
            </svg>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function () {
            const startBtn = document.getElementById('startBtn');
            const pauseBtn = document.getElementById('pauseBtn');
            const resetBtn = document.getElementById('resetBtn');
            const steps = document.querySelectorAll('.step-text');
            const svgs = [
                document.getElementById('proofSvg1'),
                document.getElementById('proofSvg2'),
                document.getElementById('proofSvg3'),
                document.getElementById('proofSvg4'),
                document.getElementById('proofSvg5')
            ];

            let currentStep = 0;
            let animationPaused = false;
            let animationInterval;

            // 初始化所有步骤为不可见
            steps.forEach((step, index) => {
                if (index !== 0) step.style.display = 'none';
                step.classList.remove('visible');
            });

            // 开始动画
            startBtn.addEventListener('click', function () {
                startBtn.disabled = true;
                pauseBtn.disabled = false;
                resetBtn.disabled = false;

                // 显示第一步
                steps[0].style.display = 'block';
                setTimeout(() => {
                    steps[0].classList.add('visible');
                }, 100);

                // 开始动画循环
                animationInterval = setInterval(nextStep, 3000);
            });

            // 暂停/继续动画
            pauseBtn.addEventListener('click', function () {
                if (animationPaused) {
                    // 继续动画
                    animationInterval = setInterval(nextStep, 3000);
                    pauseBtn.textContent = '暂停';
                } else {
                    // 暂停动画
                    clearInterval(animationInterval);
                    pauseBtn.textContent = '继续';
                }
                animationPaused = !animationPaused;
            });

            // 重置动画
            resetBtn.addEventListener('click', function () {
                clearInterval(animationInterval);
                currentStep = 0;
                animationPaused = false;
                pauseBtn.disabled = true;
                pauseBtn.textContent = '暂停';
                startBtn.disabled = false;

                // 重置所有步骤
                steps.forEach((step, index) => {
                    step.style.display = index === 0 ? 'block' : 'none';
                    step.classList.remove('visible');
                });

                // 重置第一步
                setTimeout(() => {
                    steps[0].classList.add('visible');
                }, 100);

                // 重置SVG动画
                svgs.forEach(svg => {
                    const animations = svg.querySelectorAll('animate, animateTransform');
                    animations.forEach(anim => {
                        anim.beginElement();
                    });
                });
            });

            // 下一步
            function nextStep() {
                // 隐藏当前步骤
                steps[currentStep].classList.remove('visible');

                // 移动到下一步
                currentStep = (currentStep + 1) % steps.length;

                // 显示新步骤
                steps.forEach((step, index) => {
                    step.style.display = index === currentStep ? 'block' : 'none';
                });

                setTimeout(() => {
                    steps[currentStep].classList.add('visible');
                }, 100);

                // 重置SVG动画
                svgs.forEach(svg => {
                    const animations = svg.querySelectorAll('animate, animateTransform');
                    animations.forEach(anim => {
                        anim.beginElement();
                    });
                });

                // 如果是最后一步，停止动画
                if (currentStep === steps.length - 1) {
                    clearInterval(animationInterval);
                    pauseBtn.disabled = true;
                    startBtn.disabled = false;
                }
            }
        });
    </script>
</body>

</html>